package com.ytf.core.web.controller;

import com.ytf.core.common.Resp;
import com.ytf.core.web.application.PermissionAppService;
import com.ytf.core.web.pojo.dto.PermissionDto;
import com.ytf.core.web.pojo.vo.PermissionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 权限表 前端控制器
 * </p>
 *
 * @author YTF
 * @since 2025-05-20
 */
@RestController
@RequestMapping("/api/permission")
public class PermissionController {

    @Autowired
    private PermissionAppService permissionAppService;

    @PostMapping
    public Resp<Void> insertPermission(@RequestBody PermissionDto permissionDto){
        Boolean aBoolean = permissionAppService.insertPermission(permissionDto);
        return aBoolean ? Resp.success():Resp.error();
    }

    @DeleteMapping("/{id}")
    public Resp<Void> deletePermissionById(@PathVariable String id){
        permissionAppService.deletePermissionById(Long.valueOf(id));
        return Resp.success();
    }

    @PutMapping("/{id}")
    public Resp<Void> updatePermission(@PathVariable String id ,@RequestBody PermissionDto permissionDto){
        Boolean aBoolean = permissionAppService.updatePermissionById(Long.valueOf(id),permissionDto);
        return aBoolean ? Resp.success():Resp.error();
    }

    @GetMapping("/{id}")
    public Resp<PermissionVo> getPermissionById(@PathVariable String id){
        PermissionVo permissionVo = permissionAppService.getPermissionById(Long.valueOf(id));
        return permissionVo != null ? Resp.success(permissionVo):Resp.error();
    }

}
